package com.ruicar.afs.cloud.batch.dayend.handle.run;

import cn.hutool.core.date.DateUtil;
import com.ruicar.afs.cloud.common.modules.contract.enums.LendingDirection;
import com.ruicar.afs.cloud.common.vo.AccountVoucherInfoVo;
import com.ruicar.afs.cloud.common.voucher.processor.AbsBaseRequestMsg;
import com.ruicar.afs.cloud.common.voucher.processor.IRequest;
import com.ruicar.afs.cloud.voucher.dto.VoucherSendInfoDto;
import lombok.Data;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author infinity
 * @version 1.0
 * @date 2020/7/21 21:10
 */
@Data
public class VoucherBathRequest extends AbsBaseRequestMsg {
    /**
     * 凭证实体
     */
    private List<AccountVoucherInfoVo> vos;

    public IRequest get() {
        List<VoucherSendInfoDto> sendInfoDtos = vos.stream().map(accountVoucherInfoVo -> {
            VoucherSendInfoDto dto = new VoucherSendInfoDto();
            dto.setVchNo(accountVoucherInfoVo.getVoucherNo());//凭证号
            dto.setVchId(accountVoucherInfoVo.getEntryNo().toString()); //分录号
            dto.setTransDate(DateUtil.formatDate(accountVoucherInfoVo.getPostingDate())); //记账日期
            dto.setAccountCd(accountVoucherInfoVo.getSubjectCode());//科目
            dto.setContractNo(accountVoucherInfoVo.getContractNo());//合同号
            dto.setDealerName(accountVoucherInfoVo.getDealerName());
//            dto.setProducts(voucherInfo.);//金融产品
             dto.setTypeName(accountVoucherInfoVo.getCaseType());//案件类型
            dto.setDept(accountVoucherInfoVo.getSourceSystem());//系统代码
            if (accountVoucherInfoVo.getLendingDirection().equals(LendingDirection.DEBIT)) {
                dto.setAmount(accountVoucherInfoVo.getDebitAmt());//金额
                dto.setDcCd("0");// 借贷方0、1
            } else {
                dto.setAmount(accountVoucherInfoVo.getCreditAmt());//金额
                dto.setDcCd("1");// 借贷方0、1
            }
            dto.setPostingDate(DateUtil.formatDateTime(new Date()));//同步时间
            dto.setPreparerNo(accountVoucherInfoVo.getSourceSystem());//制单人
            dto.setExplanation(accountVoucherInfoVo.getExplanation());//摘要
            dto.setEventCode(accountVoucherInfoVo.getChildBusinessCode());//事件代码
            dto.setRefNum(dto.getVchNo() + dto.getVchId());//唯一标识
            return dto;
        }).collect(Collectors.toList());
        return IRequest.success(sendInfoDtos);
    }
}
